//
//  MineFansView.swift
//  maosheng
//
//  Created by lxl on 2019/8/12.
//

import UIKit

class MineFansView: MineAttentionView {

    override func getTheAttentionList(isHeader: Bool) {
        isFans = true
        str_url = "api/services/app/Follower/GetMyFollowerPagingListAsync"
        super.getTheAttentionList(isHeader: isHeader)
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifer) as! AttentionCell
        let model = self.dataSource[indexPath.row] as? AttentinModel
        cell.attentionBtn.addTarget(self, action: #selector(followUser(btn:)), for: .touchUpInside)
        cell.setTheAttentionInfo(model: model!)
        if let isfollow = model?.followEachOther {
            cell.attentionBtn.setTitle(isfollow ? "相互关注" : "+ 关注", for: .normal)
        }
        cell.attentionBtn.tag = 101 + indexPath.row

        return cell
    }
    
    @objc func followUser(btn:UIButton)  {
        let btnTag = btn.tag - 101
        let str_url = "api/services/app/Follower/FollowAsync"
        let model = self.dataSource[btnTag] as? AttentinModel
        var params = [String : Any]()
        params["moduleTypeId"] = 100101
        params["followedObjectId"] = model?.creatorUserId
        
        SDataCenter.shared.SPostJsonDataWithUrl(str_url: str_url, params: params) { [weak self] (responseData, isSuccess) in
            if isSuccess{
//                self?.dataSource.removeObject(at: btnTag)
                let cell = self?.tableView.cellForRow(at: IndexPath(row: btnTag, section: 0)) as? AttentionCell
                cell?.attentionBtn.setTitle("相互关注", for: .normal)
            }
        }
    }
}
